#ifndef TABLEMODEL_H
#define TABLEMODEL_H

#include <QAbstractTableModel>
class TableModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    enum PlayType{
        ROUND,
        SINGLE
    };
    TableModel();
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
    QModelIndex getBackData(QModelIndex &curIndex, PlayType type = ROUND);
    QModelIndex getNextData(QModelIndex &curIndex, PlayType type = ROUND);
    QModelIndex setMusicMsg(QString fileName, QMap<QString, QString> *musicMsg);
    bool loadData();
    bool saveData();
    QString getFileNameByIndex(const QModelIndex &index);
    QModelIndex getIndexByFileName(const QString fileName);
private:
    QString localPath;
    QMap<QString, QMap<QString, QString> *> musicMsgMap;
    QString columnHeaders[3] = {"标题", "艺术家", "长度"};
    QString columnHeadersSt[3] = {"ti", "ar", "len"};
};

#endif // TABLEMODEL_H
